package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.SysOfCode;
import com.sale.system.service.ISysOfCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 编码生成配置
 *
 * @author hl
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/code")
public class SysOfCodeController extends BaseController{

    private final ISysOfCodeService sysOfCodeService;

    /**
     * 获取编码配置
     */
    //@SaCheckPermission("system:codeRule:list")
    @GetMapping("/list")
    public TableDataInfo<SysOfCode> list(SysOfCode ofCode , PageQuery pageQuery)
    {
        return sysOfCodeService.selectOfCodeList(ofCode,pageQuery);
    }


    /**
     * 获取编码配置(无分页)
     */
    @GetMapping("/listThe")
    public R<List<SysOfCode>> listThe(){
        List<SysOfCode> list = sysOfCodeService.selectOfCodeListBy();
        return R.ok(list);
    }

    /**
     * 下拉
     */
    @GetMapping("/listSel")
    public R<List<PullDown>> list()
    {
        List<PullDown> list = sysOfCodeService.selectOfCodeSelList();
        return R.ok(list);
    }

    /**
     * 新增编码配置
     */
    //@SaCheckPermission("system:codeRule:add")
    @Log(title = "编码配置", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysOfCode sysOfCode) throws Exception {
        return toAjax(sysOfCodeService.ofCodeAdd(sysOfCode));
    }

    /**
     * 删除编码
     */
    //@SaCheckPermission("system:codeRule:remove")
    @Log(title = "删除配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ofCodeId}")
    public R<Void> remove(@PathVariable("ofCodeId") String ofCodeId) throws Exception {
        return toAjax(sysOfCodeService.deleteOfCodeById(ofCodeId));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("system:codeRule:query")
    @GetMapping(value = "/{ofCodeId}")
    public SysOfCode getInfo(@PathVariable Long ofCodeId)
    {
        return sysOfCodeService.selectOfCodeById(ofCodeId);
    }

    /**
     * 修改配置
     */
    //@SaCheckPermission("system:codeRule:edit")
    @Log(title = "修改配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody SysOfCode sysOfCode) throws Exception {
        return toAjax(sysOfCodeService.updateOfEdit(sysOfCode));
    }


}
